using System;
using System.Collections.Generic;
using System.Text;
using SlimDX;
using System.Globalization;
using Barrage.Global;

namespace Barrage.GUI
{
    sealed class GUIHelper
    {
        private GUIHelper() { }
        public static Vector2 ParseVector2(string x, string y, Vector2 defaultValue)
        {
            Vector2 value = defaultValue;
            if (x != null)
            {
                    bool percent = false;
                    int percentPos = x.IndexOf('%');
                    if (percentPos >= 0)
                    {
                        percent = true;
                        x=x.Remove(percentPos);
                    }
                    float vX;
                    if (Single.TryParse(x, NumberStyles.Float, NumberFormatInfo.InvariantInfo, out vX)) value.X = vX;
                    if (percent) value.X *= Engine.DefaultRenderTargetDescription.Width / 100.0f;
            }
            if (y != null)
            {
                    bool percent = false;
                    int percentPos = y.IndexOf('%');
                    if (percentPos >= 0)
                    {
                        percent = true;
                        y=y.Remove(percentPos);
                    } 
                    float vY;
                    if (Single.TryParse(y, NumberStyles.Float, NumberFormatInfo.InvariantInfo, out vY)) value.Y = vY;
                    if (percent) value.Y *= Engine.DefaultRenderTargetDescription.Height / 100.0f;
            }
            return value;
        }
    }
}
